<template>
	<view class="contain">

		<view class="bg-color-w padding-lr12 ">
			<view class="bg-color-w padding-tb12 flex f-j-s f-a-c b-bottom" v-if="user">
			    <view class="flex f-s-0 w-50 h-50 b-radius bg-img margin-r12" :style="user.headImg | bgimg(300)+''"></view>
				<view class="flex flex-1 f-c">
					<view class="f16-size" style="width:400rpx;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;">{{user.nickname}}</view>
					<view class="margin-t2" style="width:400rpx;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;">{{i18n['用户名']}}：{{user.code | hideCenterText}}</view>
				</view>

			</view>

		</view>




		<view class="bg-color-w padding-12">
			<view class="padding-lr20">
				<view class="">追加金额</view>




						<view class="flex-col space-y-11">
							<view class="flex-row justify-between space-x-16">
								<view class="flex-col justify-center items-center text-wrapper_7  margin-t10"
@click="selectAmount(index)" :class="{'text-wrapper_active': amount_index==index }" v-for="item,index in amountArray">
									<text class="font_6 text_11">{{item}}</text>
								</view>
							</view>
						</view>




				<view class="flex f-a-c margin-t12">
					<text class="flex f-s-0 margin-r12 f32-size">￥</text>
					<view class="flex flex-1 h-70">
						<input v-model="amount" type="number" value="" class="input" style="font-size: 50px;" />
					</view>
				</view>

			</view>
		</view>
		<payItem ref="payitem" class="padding-lr20 margin-t12" :isBalance="true" ></payItem>
		<view class="padding-30 margin-t12">
			<view @click="recharge()" class="flex f-a-c f-j-c h-40 f15-size bg-color-linear-y t-color-w b-radius-5">追加</view>
		</view>
	</view>
</template>
<style scoped>
/* @import url('@/static/css/index/index.css'); */



	.text-wrapper_7 {
		padding: 16rpx;
		background-color: #ededed;
		border-radius: 10rpx;
		width:90rpx;

		height: 80rpx;
		font-size: 24rpx;
		font-family: HarmonyOSSansSC;
		line-height: 22rpx;
		color: #000000;
	}



	.text-wrapper_active {
		background-color: #ffbd52;
		color: #fff;

	}

	.text-wrapper_active .font_6 {}
</style>
<script>
	import payItem from '@/components/common/payitem.vue';
	const API = require('@/utils/api/user.js').default;
	const ORDERAPI = require('@/utils/api/tyOrder.js').default;
	
	const $ = require('@/utils/api.js');
	let self;
	export default {
		data() {
			return {
				orderNo:"",
				order: '',
				user:null,
				amount: '',
				amountArray: ["5", "10", "15", "20", "25", "其他"],
				amount_index:0,
				payTypeList: {
					order_ali_pay:"1",
					order_balance_pay: "1",
					order_wechat_pay: "1",
				},
			};
		},
		onLoad: function(options) {
			self = this;
			
				this.orderNo = options.orderNo ? options.orderNo : '';
				
			this.init();
			$.setTitle("追加");



			self.id = options.id

			this.amount = this.amountArray[this.amount_index]


			self.getUserInfo()
		},
		methods: {
			selectAmount(index) {
				this.amount_index = index
					this.amount = this.amountArray[this.amount_index]
			},


			getUserInfo() {
				const self = this;
				$.ajax({
					url: API.userByIdApi,
					data: {
						memberId: self.id,
					},
					method: 'GET',
					success(res) {
						console.log("getUser",res)
						self.user = res.data;
					}
				})
			},
			async recharge() {
				// if (this.payTypeList.order_ali_pay === '0' && this.payTypeList.order_wechat_pay === '0') return;

				let  order_group = "tyOrderAdd"

				const self = this;
				if(self.amount == '') {
					$.$toast('请输入追加金额');return;
				}

				let type = this.$refs.payitem.type;
				console.log("type:",type)
				switch (type) {
					case 'wxPay': // 微信支付
						await this.$mPayment.weixinPay(order_group,  {	memberId: self.id,amount: self.amount,	order: self.orderNo,payMethod: self.$refs.payitem.type}, '/pages/ys/order/entrust', this.code);
						break;
					case 'aliPay': // 支付宝支付
						await this.$mPayment.aliPay(order_group, {	
							memberId: self.id,amount: self.amount,
							payMethod: self.$refs.payitem.type,
							order: self.orderNo,
							}, '/pages/ys/order/entrust');
						break;
					case "balance":
						await this.$mPayment.balancePay( order_group,{	memberId: self.id, amount: self.amount,order: self.orderNo,payMethod: self.$refs.payitem.type},'/pages/ys/order/entrust');
						break;
					default:
						break;
				}
			},
			getDetail() {
				$.ajax({
					url: ORDERAPI.orderDetailApi,
					data: {
						orderNo: self.orderNo
					},
					method: 'GET',
					success(res) {
						   self.order = res.data.order
					}
				})
			},
			init() {
				// this.getDetail();
			}
		},
		// computed: {
		// 	i18n() {
		// 		return this.$t('money')
		// 	},
		// },
		created() {
		},
		mounted() {},
		destroyed() {},
		components: {payItem},
		onPullDownRefresh() {
		},
		onReachBottom() {
		}
	}
</script>
